package com.focus.xyz.other.cases;

import com.focus.xyz.core.common.webdriver.DriverFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.os.WindowsUtils;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * Created by cimon on 2016/5/9.
 */
public class RemoteTest {
    private WebDriver driver;

    @Parameters({"browser","nodeUrl"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String browser,String nodeUrl) throws Exception{
        driver = DriverFactory.getRemoteDriver(nodeUrl).getBrowser(browser);
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.get("https://www.baidu.com");
    }

    @AfterMethod(alwaysRun = true)
    public void tearDown(){
        try{
            if(driver!=null){
                driver.close();
                driver.quit();
            }
        }catch (Exception e){
            WindowsUtils.tryToKillByName("iexplore.exe");
        }

    }

    @Test
    public void testRemoteDriver(){
        driver.findElement(By.id("kw")).sendKeys("selenium");
        driver.findElement(By.id("su")).click();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Assert.assertEquals("selenium_百度搜索",driver.getTitle());
    }
}
